<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.Project"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="db.ProjectDAO"%>
<%@page import="db.SubstoreDAO" %>
<%@page import="db.OutreqDAO" %>
<%@page import="db.RetreqDAO" %>
<%@page import="db.Retreq" %>
<%@page import="db.Outreq" %>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	request.setCharacterEncoding("utf-8");
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	OutreqDAO outreqDAO = (OutreqDAO)ctx.getBean("OutreqDAO");
	RetreqDAO retreqDAO = (RetreqDAO)ctx.getBean("RetreqDAO");
	//test
	int pn=0;
	String pagenem = request.getParameter("pageNo");
	if(pagenem==null || "".equals(pagenem)){
		pn=0;
	}else{
		pn = Integer.parseInt(pagenem);
	}
	//每页多少条
	int pageSize = 10;
	//Map map = purreqDAO.getPurreqByWhere(pn,pageSize);
	//Map map =purreqDAO.getPurreq();
	int tid = (Integer)session.getAttribute("tid");
	String reqCode = request.getParameter("reqCode");
	List listob = new ArrayList();
	String pselect = request.getParameter("pselect");
	String sodate = request.getParameter("sodate");
	String pname = request.getParameter("pname");
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	
	List ob = new ArrayList();
	
	ob.add(new Object[]{"eq","phase",4});//步骤
	ob.add(new Object[]{"eq","teamId",tid});
	
	
	if((pselect=="1" || "1".equals(pselect)) && pname!=null){//选择项目名称
		ob.add(new Object[]{"like","op.name",pname});
	}
	
	if((pselect=="2" || "2".equals(pselect)) && pname!=null){//选择申请单编码
		ob.add(new Object[]{"like","reqCode",pname});
	}
	
	if(sodate!=null &&!"".equals(sodate)){
		Date date = sdf.parse(sodate);
		ob.add(new Object[]{"eq","reqDate",date});
	}

	Map map = retreqDAO.getRetreq(pn,pageSize,
	new String[][]{new String[]{"desc","reqDate"}},
	ob,
	new String[][]{new String[]{"","id"},new String[]{"","okState"},new String[]{"","reqCode"},new String[]{"","op.code"},new String[]{"","op.name"},new String[]{"","reqDate"},new String[]{"","okDate"},new String[]{"","assDate"}},
	new String[]{"outreq","project"}
	);
	Map vmMap = new HashMap();
	
	List li = (List) map.get("data");
	//System.out.println("sizesizesizesizesizesize====="+li.size());
	vmMap.put("data",getListReMap(li));
	
	int pageTotal = (Integer)map.get("pageTotal");
	int pageNo = (Integer)map.get("pageNo");
	List pageList=getPage(pageTotal,pageNo);
	request.setAttribute("map",vmMap);
	request.setAttribute("pages",pageList);
	request.setAttribute("sodate",sodate);
	request.setAttribute("pselect",pselect);
	request.setAttribute("pname",pname);
	
	pageContext.forward("/vm/returnStock/retList_3.vm");
%>
<%!
	public List getListReMap(List list){
		List listmap = new ArrayList();
		//System.out.println("===============>>>>>>>>");
		if(list != null && list.size()>0){
		
			for(int i=0;i<list.size();i++){
			
				Map map = new HashMap();
				Object[] aa= (Object[]) list.get(i);
				map.put("pid", aa[0]);
				map.put("pstate", aa[1]);
				map.put("pcode", aa[2]);
				map.put("procode", aa[3]);
				map.put("proname", aa[4]);
				SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd"); 
				if(aa[5]!=null){
					map.put("pdate", sf.format(aa[5]));
				}
				
				if(aa[6]!=null){
					map.put("penddate", sf.format(aa[6]));
				}
				if(aa[7]!=null){
					map.put("assdate", sf.format(aa[7]));
				}
				listmap.add(map);
			}
		}
		return listmap;
	}
%>